index.d.ts ➔ pack   A
last analyzed

Complexity

Conditions 1

Size

Total Lines 13
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 4
dl 0
loc 13
rs 10
c 0
b 0
f 0
cc 1
1
// Type definitions for utf8-buffer 1.0.0
2
// Project: https://github.com/rochars/byte-data
3
// Definitions by: Rafael da Silva Rocha <https://github.com/rochars>
4
// Definitions: https://github.com/rochars/utf8-buffer
5
6
/**
7
 * Read a string of UTF-8 characters from a byte buffer.
8
 * Invalid characters are replaced with 'REPLACEMENT CHARACTER' (U+FFFD).
9
 * @see https://encoding.spec.whatwg.org/#the-encoding
10
 * @see https://stackoverflow.com/a/34926911
11
 * @param {!Uint8Array|!Array<number>} buffer A byte buffer.
12
 * @param {number=} start The buffer index to start reading.
13
 * @param {?number=} end The buffer index to stop reading.
14
 *   Assumes the buffer length if undefined.
15
 * @return {string}
16
 */
17
export function unpack(
18
	buffer: Uint8Array|number[],
19
	start: number,
20
	end?: number): string;
21
22
/**
23
 * Write a string of UTF-8 characters to a byte buffer.
24
 * @see https://encoding.spec.whatwg.org/#utf-8-encoder
25
 * @param {string} str The string to pack.
26
 * @param {!Uint8Array|!Array<number>} buffer The buffer to pack the string to.
27
 * @param {number=} index The buffer index to start writing.
28
 * @return {number} The next index to write in the buffer.
29
 */
30
export function pack(
31
	str: string,
32
	buffer: Uint8Array|number[],
33
	index?: number): number;
34